package com.itlong.cloud.operate.resource;

import com.itlong.cloud.POJO.DTO.operate.*;
import com.itlong.cloud.POJO.VO.operate.WwLyOperateAppInfoVO;
import com.itlong.cloud.POJO.VO.operate.WwOperateAppInfoVO;
import com.itlong.cloud.POJO.VO.operate.WwOperateDeveloperAccountVO;
import com.itlong.cloud.POJO.VO.operate.WwOperateProjectInfoVO;
import com.itlong.cloud.operate.service.IOperateWwAppService;
import com.itlong.cloud.project.operate.IOperateWwAppServiceClient;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.regex.Pattern;

/**
 * <des>
 *     应用暴露接口视线里
 * <des>
 *
 * @create Date 2021-08-18
 **/
@RestController
public class OperateWwAppServiceResource implements IOperateWwAppServiceClient {

    @Autowired
    IOperateWwAppService iOperateWwAppService;
    /**
     * <desc>
     * 获取应用列表
     * </desc>
     *
     * @param wwOperateSelectAppDTO
     * @return: com.itlong.cloud.utils.page.Page<com.itlong.cloud.POJO.VO.operate.WwOperateAppInfoVO>
     * @author LiuYu
     * @date: 2021-08-18
     **/
    @Override
    @RequestMapping(path = "/operate/getAppPageList", method = RequestMethod.POST)
    public Page<WwLyOperateAppInfoVO> getAppPageList(@RequestBody WwOperateSelectAppDTO wwOperateSelectAppDTO) {
        try {
            return iOperateWwAppService.getAppPageList(wwOperateSelectAppDTO);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * <desc>
     * 创建应用
     * </desc>
     *
     * @param wwLyOperateCreateAppInfoDTO
     * @return: java.lang.Integer
     * @author LiuYu
     * @date: 2021-08-19
     **/

    @Override
    @RequestMapping(path = "/operate/saveAppInfo", method = RequestMethod.POST)
    public Integer save(@RequestBody WwLyOperateCreateAppInfoDTO wwLyOperateCreateAppInfoDTO) throws Exception {
        return iOperateWwAppService.save(wwLyOperateCreateAppInfoDTO);
    }

    /**
     * <desc>
     * 修改应用
     * </desc>
     *
     * @param wwLyOperateUpdateAppInfoDTO
     * @return: java.lang.Integer
     * @author LiuYu
     * @date: 2021-08-19
     **/
    @Override
    @RequestMapping(path = "/operate/updateAppInfo", method = RequestMethod.POST)
    public Integer update(@RequestBody WwLyOperateUpdateAppInfoDTO wwLyOperateUpdateAppInfoDTO) throws Exception {
        return iOperateWwAppService.update(wwLyOperateUpdateAppInfoDTO);
    }

    /**
     * <desc>
     * 添加开发者账号
     * </desc>
     *
     * @param wwLyCreateDeveloperAccountDTO
     * @return: java.lang.Integer
     * @author LiuYu
     * @date: 2021-08-19
     **/
    @Override
    @RequestMapping(path = "/operate/saveDeveloper",method = RequestMethod.POST)
    public Integer saveDeveloperAccount(@RequestBody WwLyCreateDeveloperAccountDTO wwLyCreateDeveloperAccountDTO) throws Exception {
        return iOperateWwAppService.saveDeveloperAccount(wwLyCreateDeveloperAccountDTO);
    }

    /**
     * <desc>
     * 安全设置
     * </desc>
     *
     * @param ipAddresses
     * @param appId
     * @return: java.lang.Integer
     * @author LiuYu
     * @date: 2021-08-23
     **/
    @Override
    @RequestMapping(path = "/operate/setSecurity", method = RequestMethod.POST)
    public Integer updateSecuritySetting(@RequestParam("ipAddresses") String ipAddresses,@RequestParam("appId") String appId) {
        return iOperateWwAppService.updateSecuritySetting(ipAddresses,appId);
    }

    /**
     * <desc>
     * 启用禁用
     * </desc>
     *
     * @param status
     * @param appId
     * @return: java.lang.Integer
     * @author LiuYu
     * @date: 2021-08-23
     **/
    @Override
    @RequestMapping(path = "/operate/setStatus", method = RequestMethod.POST)
    public Integer updateStatus(@RequestParam("status") Integer status,@RequestParam("appId") String appId) {
        return iOperateWwAppService.updateStatus(status, appId);
    }

    /**
     * <desc>
     * 有效期授权
     * </desc>
     *
     * @param wwLyOperateUpdateEffectTimeDTO
     * @return: java.lang.Integer
     * @author LiuYu
     * @date: 2021-08-23
     **/
    @Override
    public Integer updateEffectTime(@RequestBody WwLyOperateUpdateEffectTimeDTO wwLyOperateUpdateEffectTimeDTO) throws Exception {
        return iOperateWwAppService.updateEffectTime(wwLyOperateUpdateEffectTimeDTO);
    }

//    /**
//     * <desc>
//     * 上传图片
//     * </desc>
//     *
//     * @param file
//     * @return: java.lang.String
//     * @author LiuYu
//     * @date: 2021-08-19
//     **/
//    @Override
//    @RequestMapping(path = "/operate/uploadImage",method = RequestMethod.POST,consumes = "multipart/form-data")
//    public String uploadImage(@RequestPart("file") MultipartFile file) throws IOException {
//        return iOperateWwAppService.uploadImage(file);
//    }

    /**
     * <desc>
     * 查询开发者账号列表
     * </desc>
     *
     * @param wwOperateSelectDeveloperAccountDTO
     * @return: com.itlong.cloud.utils.page.Page<com.itlong.cloud.POJO.VO.operate.WwOperateDeveloperAccountVO>
     * @author LiuYu
     * @date: 2021-08-19
     **/
    @Override
    @RequestMapping(path = "/operate/getDeveloperAccountPageList",method = RequestMethod.POST)
    public Page<WwOperateDeveloperAccountVO> getDeveloperAccountPageList(@RequestBody WwOperateSelectDeveloperAccountDTO wwOperateSelectDeveloperAccountDTO) throws Exception {
        return iOperateWwAppService.getDeveloperAccountPageList(wwOperateSelectDeveloperAccountDTO);
    }

//    /**
//     * <desc>
//     * 查询项目列表
//     * </desc>
//     *
//     * @param wwOperateSelectProjectDTO
//     * @return: com.itlong.cloud.utils.page.Page<com.itlong.cloud.POJO.VO.operate.WwOperateProjectInfoVO>
//     * @author LiuYu
//     * @date: 2021-08-19
//     **/
//    @Override
//    @RequestMapping(path = "/operate/getProjectPageList", method = RequestMethod.POST)
//    public Page<WwOperateProjectInfoVO> getProjectPageList(@RequestBody WwOperateSelectProjectDTO wwOperateSelectProjectDTO) throws Exception {
//        return iOperateWwAppService.getProjectPageList(wwOperateSelectProjectDTO);
//    }
}
